<!--全局组件弹窗，确认和取消-->
<template>
  <v-dialog v-model="showDialog" max-width="500">
    <v-card>
      <!-- 弹窗标题 -->
      <v-card-title>{{ title }}</v-card-title>
      <!-- 弹窗内容 -->
      <v-card-text class="d-flex justify-center">{{ content }}</v-card-text>
      <v-card-actions
      class="d-flex justify-space-evenly">
        <!-- 确定按钮 -->
        <v-btn  @click="handleConfirm">确定</v-btn>
        <!-- 取消按钮 -->
        <v-btn color="primary" @click="closeDialog">取消</v-btn>
      </v-card-actions>
    </v-card>
  </v-dialog>
</template>

<script>
export default {
  name: "globalDialog",
  data() {
    return {
      showDialog: false,
      title: '',
      content: '',
      resolve: null,
      reject: null
    };
  },
  methods: {
    openDialog(title, content) {
      this.title = title;
      this.content = content;
      this.showDialog = true;
      return new Promise((resolve, reject) => {
        this.resolve = resolve;
        this.reject = reject;
      });
    },
    /**
     * 点击取消结果是 false
     */
    closeDialog() {
      this.showDialog = false;
      this.reject(false);
    },
    /**
     * 点击确定结果是 true
     */
    handleConfirm() {
      this.showDialog = false;
      this.resolve(true);
    }
  }
};
</script>
